package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.Platenumber;
import com.ruoyi.system.domain.TInandout;
import com.ruoyi.system.mapper.TInandoutMapper;
import com.ruoyi.system.service.ITInandoutService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Xiexingxie
 * @date 2022/12/12 上午 09:46
 */

@Service
public class TInandoutServiceImpl implements ITInandoutService {

    private final static Logger log = LoggerFactory.getLogger(TInandoutServiceImpl.class);

    @Autowired
    private TInandoutMapper inandoutMapper;


    @Override
    public List<TInandout> selectAllInandoutInfo(TInandout inandout) {
        return inandoutMapper.selectAllInandoutInfo(inandout);
    }

    @Override
    public TInandout selectTCarportById(Integer iid) {
        return inandoutMapper.selectTCarportById(iid);
    }

    @Override
    public int insertTinandout(TInandout tInandout) {
        return inandoutMapper.insertTinandout(tInandout);
    }

    @Override
    public int updateTinandout(TInandout tInandout) {
        return inandoutMapper.updateTinandout(tInandout);
    }

    @Override
    public int deleteTinandoutByIid(Integer iid) {
        return inandoutMapper.deleteTinandoutByIid(iid);
    }

    @Override
    public int deleteTinandoutByIids(Integer[] iids) {
        return inandoutMapper.deleteTinandoutByIids(iids);
    }

    @Override
    public boolean insertInsPlatenumber(TInandout tInandout) {
        String platenumber = tInandout.getPlatenumber();
        String str = inandoutMapper.selectTplatenumberWithInandoutByplatenumber(platenumber);
        log.debug("根据车牌拿到的数据为：{}", str);
        if (platenumber.isEmpty()) {
            return false;
        }
        String s = inandoutMapper.selectInandoutByPlatenumberIsinOrNot(platenumber);
        // 判断车辆是否是从进口出进入的
        if (tInandout.getIns() == 1 || tInandout.getIns() == 3 || tInandout.getIns() == 5) {
            // 如果库中没有该车辆，则是临时车辆
            if (str == null) {
                inandoutMapper.insertInsPlatenumber2(tInandout);
            }
            // 如果库中有该车辆，则是VIP车辆
            if (str != null) {
                inandoutMapper.insertInsPlatenumber(tInandout);
            }
        }
        if (tInandout.getIns() == 2 || tInandout.getIns() == 4 || tInandout.getIns() == 6) {
            inandoutMapper.updateOutPlatenumber(tInandout.getIid());
        }
        return true;
    }
}
